home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13761 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  53 lines

  1. Path: csun.edu!kc44097
  2. From: kc44097@csun.edu (chen)
  3. Newsgroups: comp.lang.c
  4. Subject: About union
  5. Date: 10 Apr 1996 06:06:40 GMT
  6. Organization: California State University, Northridge
  7. Message-ID: <4kfj5g$24n@dewey.csun.edu>
  8. NNTP-Posting-Host: huey.csun.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11.  
  12.    I read the program below from a book and do not know how it
  13. works,can anyone give me some advice ?
  14.  
  15.    Please e-mail me : kc44097@huey.csun.edu
  16.                       Thankx ! 
  17. -----------------------------------------------------
  18.  
  19.  
  20. #include <stdio.h>
  21.  
  22. union {
  23.   int   integer;
  24.   float floating;
  25. } myUnion;
  26.  
  27.  
  28. main()
  29. {
  30.  
  31.   myUnion.integer = 1109917697;  
  32.   
  33.   (void) printf("The value of integer is %d\n",     myUnion.integer);
  34.   (void) printf("The value of floating is %f\n\n",  myUnion.floating);
  35.  
  36.   (void) printf("The value of \"cast\" is %f\n",    (float) myUnion.integer);
  37.   (void) printf("The value of \"magic\" is %f\n\n", myUnion.integer);
  38.   
  39.   (void) printf("The meaning of life ``%d''\n",     (int) myUnion.floating);
  40.   return (0);
  41. }
  42.  
  43.  
  44. // The output are :
  45.  
  46. The value of integer is 1
  47. The value of floating is 0.000000
  48.  
  49. The value of "cast" is 1.000000
  50. The value of "magic" is 0.000000
  51.  
  52. The meaning of life "0"
  53.